<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div style="text-align: center;font-size: large;">函数</div>

    <script>
         let arrA=["辞去经年","陌上花开","可缓缓归依","诗经"];
        let arrB=[1,3,5,7,9,11,13,15]
        let arrC=[2,4,6,8,10,12,14,16]
        let arrD=[1,2,3,4]
        let arrE=[12,34,56,78]
        let arrF=[23,34,45,56]
        let arrG=[34,45,67,78]
        let arrH=[21,43,65,87]
        let arrI=[31,42,64,53]
        let arrJ=[24,36,47,58]
        let arrK=[123,234,345,456,567,678,678]
        let arrL=[321,432,543,654,765,876,987,111]
        let arrM=[1,2,3,4,5,6,7]

        //includes判断数组中是否包含指定值，返回布尔值&nbsp;
        let colors = ["粉", "淡绿", "天蓝", "白"];
        let hasLightGreen = colors.includes("淡绿");
        let hasPink = colors.includes("粉");
        console.log(hasLightGreen); 
        console.log(hasPink); 

        //every判断数组是否所有元素都符合回调条件，返回布尔值
        let allEvery1=arrB.every(item=>item<=7)
        let allEvery2=arrB.every(item=>item<5)
        console.log(allEvery1)
        console.log(allEvery2)

        //截取数组片段
        let slicedArr=arrA.slice(0)
        console.log(slicedArr)  
        let slicedArr1=arrA.slice(1)
        console.log(slicedArr1)

        //some判断数组至少有一个元素符合回调条件，返回布尔值
        let hasSome1=arrC.some(item=>item%2===0)
        console.log(hasSome1)
        let hasSome2=arrD.some(item=>item%3===0)
        console.log(hasSome2)
        
        //reduce累加/归约数组，接受回调和初始值，返回最终归约3结果
        let sum1=arrG.reduce((acc,item)=>acc+item,0)
        console.log(sum1)
        let sum2=arrH.reduce((acc,item)=>acc+item,0)
        console.log(sum2)

        //find查找数组中第一个符合回调条件的元素，无则返回undefined
        let firstFind1=arrE.find(item=>item>57)
        console.log(firstFind1)
        let firstFind2=arrF.find(item=>item>70)
        console.log(firstFind2)

        //filter筛选数组，返回符合回调条件的元素组成的新数组
        let evenFilter1=arrI.filter(item=>item%2===0)
        console.log(evenFilter1)
        let evenFilter2=arrJ.filter(item=>item%3===0)
        console.log(evenFilter2)
        
        //map遍历数组，返回由回调返回值组成的新数组
        let doubledMap1=arrK.map(item=>item*2)
        console.log(doubledMap1)
        let doubledMap2=arrL.map(item=>item*3)
        console.log(doubledMap2)

        // 去重函数（利用 Set）
        let uniqueArr = [...new Set(arrK)];
        console.log("原数组:", arrK);
        console.log("去重后:", uniqueArr);
    </script>
</body>
</html>